01. Routes & GET Requests
Routes & GET Requests Heading
Routes: GET Requests
ND#0001 C3 L3 A01 Routes And GET Requests
Code Demo
In this example below, app.get() is used to make a GET request, the first parameter is the particular URL -- in this case our project home page, and a callback function to execute. Inside the callback function a response is sent using .send(), and in this case the response is a string that says 'hello world'. The real life execution of this code would mean that whenever the project home URL is visited in the browser, there will be a GET request made to the server, and the response will be shown in the browser, so the words 'hello world' would appear on the screen.
var express = require('express')
var app = express()
// respond with "hello world" when a GET request is made to the homepage
app.get('/', function (req, res) {
res.send('hello world')
})